<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main" />
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <g:set var="entityName" value="${message(code: 'estate.label', default: 'Estate')}" />
    <title>发布预警</title>
    <style>
    .contact-stat{
        padding: 8px 0px;
        text-align: center;
    }
    .contact-stat span{
        font-size: 13px;
        color: #88898c;
        margin-bottom: 10px;
    }
    .contact-stat strong{
        font-size: 13px;
        word-wrap: break-word;
    }
    .nav-tabs{
        border-bottom: none;
    }
    .hpanel > .panel-footer, .hpanel > .panel-section{
        background: #f9f9f9;
    }

    .newFontSize{
        font-size: 12px;
    }
    table>tbody>tr>td, table>tbody>tr>th,.table>tfoot>tr>td, table>tfoot>tr>th, table>thead>tr>td, table>thead>tr>th{
        padding: 8px;
        line-height: 1.42857143;
    }

    </style>
</head>
<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li>CINDATA PLS</li>
                    <li class="active">
                        <span>发布预警</span>
                    </li>
                </ol>
            </div>

            <h2 class="font-light m-b-xs">
                发布预警
            </h2>
        </div>
    </div>
</div>

<div class="content animate-panel">
    <div class="row">
        <g:form method="POST" action="releasePriceFluctuationsWarning" class="form-horizontal" role="form" id="form">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <button class="btn btn-primary btn-xs" type="submit"><i class="fa fa-search"></i> 查询</button>
                        <button class="btn btn-warning2 btn-xs" type="button" id="resetBtn">
                            <i class="fa fa-times"></i> 重置</button>
                    </div>
                    查询
                </div>
                <div class="panel-body" id="bug1">
                    <div class="row">

                        <div class="form-group col-sm-4">
                            <label for="" class="col-sm-3 control-label">房屋用途</label>
                            <div class="col-sm-9">
            <g:select class="form-control" name="residentialType" id="residentialType"
                      from="${com.cindata.dictionary.BuildingTypeDict.listOrderById()}"
                      valueMessagePrefix="status" optionKey="id" optionValue="name"
                      value="${params?.residentialType}"
                      noSelection="${["": '请选择房屋用途']}"/>
            </div>
        </div>

            <div class="form-group col-sm-4">
                <label for="city" class="col-sm-3 control-label">城市</label>
                <div class="col-sm-9">
                    <g:select class="form-control" name="city" id="city"
                              from="${com.cindata.City.executeQuery("select distinct e.city as city from Estate e where e.city.id not in(2,1660)")}"
                              valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"
                              value="${params?.city}"
                              noSelection="${["-1": '请选择城市']}"/>
                    <input type="hidden" id="communityId" value="${params?.communityId}" name="communityId" />
                </div>
            </div>

            <div class="form-group col-sm-4">
                <label for="district" class="col-sm-3 control-label">行政区</label>
                <div class="col-sm-9">
                    <g:select class="form-control" name="district" id="district"
                              from="${districtList}"
                              valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name"
                              value="${params?.district}"
                              noSelection="${["-1": '请选择行政区']}"/>
                </div>
            </div>

            </div>
            </div>
        </g:form>
    </div>
    </div>

    <div class="row">
        <div class="hpanel hgreen">
            <div class="panel-heading">
                <div class="panel-tools">
                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                发布预警设置
            </div>
            <div class="panel-body no-padding">

                <div class="panel-body form-horizontal">
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <label for="district" class="col-sm-3 control-label">价值波动率</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="priceFluctuationsRatio" id="priceFluctuationsRatio"
                                          from="${com.cindata.Estate.constrainedProperties.priceFluctuationsRatio.inList}"
                                          valueMessagePrefix="status" optionKey="" optionValue=""
                                          value="${params?.priceFluctuationsRatio}"
                                          noSelection="${["": '请选择价值波动率']}"/>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="table-responsive">
                    <table cellpadding="1" cellspacing="1" class="table table-striped table-bordered table-hover text-center" id="">
                        <thead>
                        <tr>
                            <th style="width: 60px;" class="text-center sortable"><input type="checkbox" class="i-checks allCheckbox" id="allOptionId"></th>
                            <g:sortableColumn property="externalId" title="押品编号" class="text-center" params="${params}"/>
                            <g:sortableColumn property="buildingType" title="房屋用途" class="text-center" params="${params}"/>
                            <g:sortableColumn property="city" title="城市"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="district" title="行政区" class="text-center" params="${params}"/>
                            <g:sortableColumn property="sourceAddress" title="房屋坐落" class="text-center" params="${params}"/>
                            <g:sortableColumn property="buildArea" title="面积(平米)"
                                              class="text-center" params="${params}"/>
                            <g:sortableColumn property="loansAmount" title="贷款金额(元)"   class="text-center" params="${params}"/>
                            <g:sortableColumn property="loansBalance" title="贷款余额(元)"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="totalPrice" title="当前估值(元)"
                                              class="text-center" params="${params}"/>
                            <g:sortableColumn property="cltv" title="动态抵押率"  class="text-center" params="${params}"/>
                            <g:sortableColumn property="cltv" title="押品风险"  class="text-center" params="${params}"/>
                            <th class="text-center sortable" style="color: #34495e;">操作项</th>
                        </tr>
                        </thead>
                        <tbody>
                        <g:each in="${collateralList}">
                            <tr>
                                <td class="text-center"><input type="checkbox" class="i-checks everyCheckbox" name="everyCheckbox" value="${it?.estate?.id}"></td>
                                <td class="text-center">${it?.externalId}</td>
                                <td class="text-center">${it?.estate?.buildingType?.name}</td>
                                <td class="text-center">${it?.city?.name}</td>
                                <td class="text-center">${it?.district?.name}</td>
                                <td class="text-center">${it?.estate?.sourceAddress}</td>
                                <td class="text-center">${it?.estate?.buildArea}</td>
                                <td class="text-center">${it?.estate?.loansAmount}</td>
                                <td class="text-center">${it?.estate?.loansBalance}</td>
                                <td class="text-center">${it?.totalPrice}</td>
                                <td class="text-center">${it?.cltv?com.cindata.NumberUtil.GetFixedNumber(it?.cltv*100):'0.00'}%</td>
                                <td class="text-center"><g:if test="${it?.cltv>=0&&it?.cltv<=0.6}">低</g:if>
                                <g:if test="${it?.cltv>0.6&&it?.cltv<=0.8}">中</g:if>
                                <g:if test="${it?.cltv>0.8&&it?.cltv<=1}">高</g:if>
                                <g:if test="${it?.cltv>1}">损失</g:if>
                                </td>
                                <td class="text-center">
                                    <div style="margin-bottom: 2px;">
                                        <a href="${it?.estate?.id}" class="btn btn-xs btn-outline btn-success handleButton">
                                            发布预警
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        </g:each>
                        </tbody>
                    </table>
                </div>


            </div>
            <div class="panel-footer" style="height: 84px;">
                <div class="pagination" style="">
                    <g:paginate action="releasePriceFluctuationsWarning" total="${collateralCount ?: 0}" params="${params}"/>
                </div>
                <div style="display: flex;justify-content: center;">
                    <button type="button" class="btn w-xs btn-success warningButton">发布预警</button>
                    <button type="button" class="btn w-xs btn-default cancelButton" style="margin-left: 20px;">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>





<script>

    var checkAll =$('.allCheckbox');  //全选的input
    var checkboxs =$('.everyCheckbox'); //所有单选的input

    checkAll.on('ifChecked ifUnchecked',function(event){
        if(event.type == 'ifChecked'){
            checkboxs.iCheck('check');
        }else{
            checkboxs.iCheck('uncheck');
        }
    });

    checkboxs.on('ifChanged',function(event){
        if(checkboxs.filter(':checked').length == checkboxs.length){
            checkAll.prop('checked',true);
        }else{
            checkAll.prop('checked',false);
        }
        checkAll.iCheck('update');
    });
    //单条发布预警事件
    $(".handleButton").click(function(event){
        event.preventDefault();
        var id = $(this).attr("href");
        // var priceFluctuationsRatio = $("#priceFluctuationsRatio").val();
        // if(!priceFluctuationsRatio){
        //     toastr.error('请选择价值波动率！');
        //     return
        // }
        swal({
                title: "确定发布该预警吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            },
            function(){
                $.ajax({
                    url:'/riskWarning/multitermReleaseWarning',
                    data:{
                        ids:id
                    },
                    type:"post",
                    success:function(data)
                    {
                        if(data.status=="success"){
                            window.location.href="/riskWarning/priceFluctuationsRatioWarning"
                        }else{
                            swal("发布预警失败，请稍后重试", "", "error");
                        }
                    }
                })

            });
    });
    //多条发布预警事件
    $(".warningButton").click(function(){
        var ids = $("input:checkbox[name='everyCheckbox']:checked").map(function(index,elem) {
            return $(elem).val();
        }).get().join(',');
        // var priceFluctuationsRatio = $("#priceFluctuationsRatio").val();
        // if(!priceFluctuationsRatio){
        //     toastr.error('请选择价值波动率！');
        //     return
        // }
        if(!ids){
            toastr.error('请选择押品！');
            return
        }
        swal({
                title: "确定发布该预警吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            },
            function(){
                $.ajax({
                    url:'/riskWarning/multitermReleaseWarning',
                    data:{
                        ids:ids
                    },
                    type:"post",
                    success:function(data)
                    {
                        if(data.status=="success"){
                            window.location.href="/riskWarning/priceFluctuationsRatioWarning"
                        }else{
                            swal("发布预警失败，请稍后重试", "", "error");
                        }
                    }
                })
            });
    });
    //取消按钮事件
    $(".cancelButton").click(function(){
        checkboxs.iCheck('uncheck');
    });
    //城市切换事件
    $("#city").bind("change", function(){
        $("#district option").remove();
        $("#s2id_district span:first").html("请选择行政区");
        var city = $("#city").val();
        $("#district").append("<option value='-1' >请选择行政区</option>");
        if(city=='-1'){
            return
        }
        $.ajax({
            url: "/estate/districtList",
            type: "POST",
            data: {'city': city} ,
            success: function(result){
                for(var i=0; i < result.districtList.length; i++){
                    $("#district").append("<option value=" + result.districtList[i].zoneNumber + ">" + result.districtList[i].name + "</option>")
                }
            }
        });
    });
//    $("#city").change();
    //条件重置事件
    $("#resetBtn").click(function () {
        $("#s2id_residentialType span:first").html("请选择房屋用途");
        $("#residentialType").val("");
        $("#s2id_city span:first").html("请选择城市");
        $("#city").val("");
        $("#s2id_district span:first").html("请选择行政区");
        $("#district").val("");
    });
</script>

</body>
</html>
